package com.ocp.socket.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author: lichong
 * @email: li_chong@massclouds
 * @Date: 2019/3/15 10:05
 * @Description: 定时任务启动并行任务处理（多个定时任务在一个时间内可以同时进行）
 */
@Configuration
@EnableScheduling
public class ScheduleConfig implements SchedulingConfigurer {

    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        scheduledTaskRegistrar.setScheduler(scheduleTaskExecutor());
    }

    @Bean(destroyMethod = "shutdown")
    public Executor scheduleTaskExecutor() {
        return Executors.newScheduledThreadPool(10);
    }
}
